from flask import Blueprint
from flask import redirect
from flask import request
from flask import session
from flask import url_for

admin_blue = Blueprint('admin', __name__, url_prefix='/admin')

from . import views


# 在蓝图定义中添加请求钩子，实现每个admin中的路由(除login)访问前都需要获取到is_admin
@admin_blue.before_request
def check_admin():
    is_admin = session.get('is_admin', False)
    if not is_admin and not request.url.endswith(url_for('admin.login')):
        return redirect('/')
